﻿#include "mainwindow.h"
#include <QApplication>

#include "common.h"
#include "logger.h"
#include "dbservice.h"
#include <Qdir>
#include "SysCfg.h"
int init()
{
    QString currentPath = QCoreApplication::applicationDirPath();
    QDir::setCurrent(currentPath);

    Logger::sharedInstance()->cfg(LoggerLevelInfo,"log/watchDog.log", 20,20,LoggerModeOnlyBothFileAndQDebug);
    if(gDBService.openDB() == f_success)
    {
        LOG_INFO("try to open db success");
    }
    else
    {
        LOG_ERROR("try to open db failed, init fail")
        return f_fail;
    }

    if(isSocketOnListenning(LISTEN_PORT))
    {
        LOG_ERROR("port:%d is on listen, can't start it");
        return f_fail;
    }

    return f_success;
}

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    if(f_success != init())
    {
        LOG_ERROR("try to init failed, programe will exist");
        return 1;
    }

    MainWindow w;
    w.show();

    return a.exec();
}
